using System;
using System.Diagnostics.CodeAnalysis;

namespace SimpleApp.Tests;

public class Comparer
{
    public static Comparer<U?> Get<U>(Func<U?, U?, bool> compare)
    {
        return new Comparer<U?>(compare);
    }
}

public class Comparer<T> : Comparer, IEqualityComparer<T>
{
    private readonly Func<T?, T?, bool> compare;
    public Comparer(Func<T?, T?, bool> compare)
    {
        this.compare = compare;
    }
    public bool Equals(T? x, T? y)
    {
        return compare(x, y);
    }

    public int GetHashCode([DisallowNull] T obj)
    {
        return obj?.GetHashCode() ?? 0;
    }
}
